import { Device } from '../device';
import {
  DeviceState,
  DeviceErrorType,
  ChannelType,
  DeviceEventType
} from '../../common/commlib.enums';

export class MockDevice extends Device {
  public register() {
    setTimeout(() => {
      this.state = DeviceState.CONNECTED;
      this.onNewEvent$.next({
        eventType: DeviceEventType.CHANGE,
        payload: this
      });
    }, 500);
  }

  public mute() {
    //
  }

  public unmute() {
    //
  }

  public createContact(_parameters?: any): any {
    //
  }

  public joinContact(_contactId: string): any {
    //
  }

  public unregister() {
    if (this.state !== DeviceState.CONNECTED) {
      this.onError$.next({
        type: DeviceErrorType.UNREGISTER_FAILED,
        message: 'incorrect state',
        payload: null
      });
      return;
    }
    this.state = DeviceState.DISCONNECTED;
    this.onNewEvent$.next({
      eventType: DeviceEventType.CHANGE,
      payload: this
    });
  }

  public setState(_state?: DeviceState) {
    //
  }

  constructor(id: string) {
    super(id);
    this.type = ChannelType.PHONE;
    this.name = 'mock device';
    this.state = DeviceState.DISCONNECTED;
    this.address = 'mockAddress';
  }
}
